import 'package:flutter/material.dart';

class MyApp3 extends StatelessWidget {
  // 2. 设置默认值
  const MyApp3({
    super.key,
    this.title = '',
    this.content = '',
    this.tColor = Colors.orange,
    this.cColor = Colors.yellow,
  });

  // 1. 定义属性
  final String title;
  final String content;
  final Color tColor;
  final Color cColor;

  // 重写build 返回需要封装的组件即可
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.purple,
          title: Center(
            child: Text(
              '标题为:$title',
              style: TextStyle(
                  color: tColor, fontSize: 30, fontWeight: FontWeight.w900),
            ),
          ),
        ),
        // 1.2 主体部分
        body: const MyContainer(),
      ),
    );
  }
}

class MyContainer extends StatelessWidget {
  const MyContainer({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      // 设置屏幕宽度
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      // 如果设置了 decoration color 属性就要省略
      // color: Colors.blue,
      margin: const EdgeInsets.all(20),
      padding: const EdgeInsets.all(100),
      alignment: Alignment.bottomRight,
      decoration: BoxDecoration(
          color: Colors.deepPurple,
          border: Border.all(width: 20, color: Colors.orange)),
      child: const Text(
        '牛宝宝',
        style: TextStyle(fontSize: 100, fontWeight: FontWeight.w900),
      ),
    );
  }
}
